<?php 
	$total_reg = "4";
	if(isset($_GET['pg'])){
		$pg  = $_GET['pg'];
		$busca = $_GET['b'];
	}else{
		$pg = "1";
		if(isset($_POST['busca'])){
		$busca = $_POST['busca'];
		}else{
		$busca = "";
		}
	}
	$inicio = $pg - 1;
	$inicio = $inicio * $total_reg;

$sql_consulta = mysql_query("SELECT texto,titulo,foto_principal,id FROM tbl_noticias WHERE texto like '%".$busca."%' OR titulo like '%".$busca."%' UNION ALL SELECT descricao,nome,arquivo,codigo FROM tbl_subitens WHERE descricao like '%".$busca."%' OR nome like '%".$busca."%' ORDER BY id DESC LIMIT ".$inicio.",".$total_reg." ");

$sql_total = mysql_query("SELECT texto,titulo,foto_principal,id FROM tbl_noticias WHERE texto like '%".$busca."%' OR titulo like '%".$busca."%' UNION ALL SELECT descricao,nome,arquivo,codigo FROM tbl_subitens WHERE descricao like '%".$busca."%' OR nome like '%".$busca."%' ORDER BY id DESC ");

$sql_num = mysql_num_rows($sql_total);

$tp = ceil($sql_num / $total_reg); // verifica o número total de páginas

?>
<div class="content2" style="margin-top:15px;">
    <div style="background-image:url(img/top_menu2.png);width:660px;height:45px;">
    <div style="width:200px;height:30px;position:relative;left:20px;top:10px;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif;font-size:20px;color:white;">
     Resultado de Busca</div>
    </div>
	<style type="text/css">
	.aNotice {
	text-decoration:none;
	font-size:14px;
	font-family:Tahoma, Geneva, sans-serif;
	/*color:#49b4d6;*/
	color:#232323;
	}
	.aNotice:hover{
	color:#999;/*#093;*/
	}
	.aNotice:visited{
	color:#444;
	}
	#botoes{
		width:600px;
		height:50px;
		position:relative;
		/*border-top:1px solid #000;*/
		left:20px;
	}
	#div_a{
		width:34px;
		height:32px;
		position:relative;
		float:left;
		top:10px;
	}
	#div_p{
		width:34px;
		height:32px;
		left:535px;
		float:left;
		position:relative;	
		top:10px;
	}
    </style>    
    <span style="margin-left:20px;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif;font-size:14px;color:#999">Total de resultados de busca por <?php  echo "'".$busca."' : ".$sql_num; ?> </span> 
    <?php
    
    if ($sql_num > 0){
        while(list($memo,$titulo,$arq_foto,$codigo)=mysql_fetch_array($sql_consulta)){
        $v = explode('.',$arq_foto);
        if($v[1] == 'pdf'){
            $t = 'este arquivo pertence a Artigos';
            $caminho = "intranet/".$arq_foto;
            $target = "_blank";
        }else{
            $t = 'este arquivo pertence a Noticias';
            $id_n = base64_encode($codigo);
            $caminho = "index.php?pagina=slideNotice/noticias_page.php&noticia=".$id_n;	
            $target = "_self";		
        }
    ?>		
        <div style="margin-left:10px;margin-top:10px;width:660px;">
            <div style="border-bottom:1px solid #000;width:560px;float:left;position:relative;top:-15px;left:10px;">
            <p><a target="<?php echo $target; ?>" class="aNotice" href="<?php echo $caminho; ?>">
            <b><?php echo $titulo; ?></b>
            </a><br />
            <a class="aNotice" target="<?php echo $target; ?>" style="font-family:'Trebuchet MS', Arial, Helvetica, sans-serif;font-size:12px;" href="<?php echo $caminho; ?>">Leia mais</a>
            </p>
            </div>
        </div>
        <?php }
    }else{
        echo 'Nenhum resultado encontrado ';
    }
    
    ?>
        <div style="clear:both;"></div>
        <script>
        function hproximo(){document.getElementById('pro').src = "img/imagens/proximo2.png";}
        function outproximo(){document.getElementById('pro').src ="img/imagens/proximo1.png";}
        function hanterior(){document.getElementById('ant').src ="img/imagens/anterior2.png";}
        function outanterior(){document.getElementById('ant').src ="img/imagens/anterior1.png";}
        </script>
	<div id="botoes">
	<?php
		$anterior = $pg -1;
		$proximo = $pg +1;
		if ($pg > 1) {?>
        <div id="div_a">
		<?php
		echo " <a href='index.php?pagina=internas/link_busca.php&pg=$anterior&b=".$busca."'><img onmouseout=\"outanterior();\" onmouseover=\"hanterior();\"  src=\"img/imagens/anterior1.png\" id=\"ant\"/></a> ";
		?>
        </div>
		<?php }
		?>
        
        <?php
		if ($pg < $tp) {?>
        <div id="div_p">
        <?php
		echo " <a href='index.php?pagina=internas/link_busca.php&pg=$proximo&b=".$busca."'><img onmouseout=\"outproximo();\" onmouseover=\"hproximo();\" src=\"img/imagens/proximo1.png\" id=\"pro\" /></a>";
		?>
        </div>
		<?php }?>
    </div>   
        
    </div>
